import { Button, Toast } from "antd-mobile";
import React, { Component } from "react";
import Header from '../../components/Header/Header'
import { reqcartadd, reqgetgoodsinfo } from "../../http/api";
import { $pre } from "../../http/http";
import "./Goods.less"



export default class Detail extends Component {
  constructor() {
    super();
    this.state = {
      info: {},
    };
  }
  async componentDidMount() {
    let res = await reqgetgoodsinfo({ id: this.props.match.params.id });
    this.setState({
      info: res.data.list[0]
    })
  }
  // 加入购物车
  async addShop() {
    let { id, type } = this.props.match.params
    let res = await reqcartadd({
      uid: JSON.parse(sessionStorage.getItem("userInfo")).uid,
      goodsid: id,
      type,
      num: 1,
    })
    if (res.data.code === 200) {
      Toast.show({
        content: res.data.msg
      })
    }



  }
  render() {
    let { info } = this.state
    return (
      <div>
        <Header title="商品详情" back></Header>
        {/* <div dangerouslySetInnerHTML={{ __html: info.description }}></div> */}
        <div className="xiang">
          <img src={$pre + info.img} alt="" />
          <h1>限时:{info.market_price}</h1>
          <div className="da">{info.goodsname}</div>
          <div>{info.description}</div>

        </div>

        {/* cateid: 1
description: "今日附近793人在买"
discount: 1
goodsname: "国产香蕉 400g/份"
id: 1
img: "/uploads/banana.jpg"
ishot: 1
islimit: 1
isnew_user: 1
isseckill: 2
market_price: 5.99
price: 2.49
status: 1 */}

        <div className="di">
          <Button color="warning" shape='rounded' onClick={() => this.addShop()}>加入购物车</Button>
          <Button color="danger" shape='rounded'>立即购买</Button>
        </div>
      </div>
    );
  }
}

